import storage from 'store'

/**
 * 获取本地保存的配置
 * @param load {boolean} 是否加载配置中的主题
 * @returns {Object}
 */
function getLocalSetting(loadTheme) {
  let localSetting = {}
  const localSettingStr = storage.get(process.env.VUE_APP_SETTING_KEY)
  localSetting = JSON.parse(localSettingStr)
  if (loadTheme) {
    loadLocalTheme(localSetting)
  }
  return localSetting
}

/**
 * 加载本地主题
 * @param {*} localSetting
 */
function loadLocalTheme(localSetting) {
  if (localSetting && localSetting.theme) {
    let { color, mode } = localSetting.theme
    color = color || theme.color
    mode = mode || theme.mode
    changeThemeColor(color, mode)
  }
}
